From dbb734dfed459e15594bddd2abf2c7610e8345be Mon Sep 17 00:00:00 2001 From: robertl Date: Fri, 6 Oct 2006 16:30:25 +0000 Subject: [PATCH] Provide xvasprintf and implement xasprintf in terms of that. --- util.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/util.c b/util.c index 7dfcb446d..f05f7d120 100644 --- a/util.c +++ b/util.c @@ -291,16 +291,15 @@ xfputs(const char *errtxt, const char *s, FILE *stream) */ int -xasprintf(char **strp, const char *fmt, ...) +xvasprintf(char **strp, const char *fmt, va_list args) { /* From http://perfec.to/vsnprintf/pasprintf.c */ /* size of first buffer malloc; start small to exercise grow routines */ #define FIRSTSIZE 64 - va_list args; - char *buf; + char *buf = NULL; size_t bufsize; char *newbuf; - size_t nextsize; + size_t nextsize = 0; int outsize; bufsize = 0; @@ -320,9 +319,7 @@ xasprintf(char **strp, const char *fmt, ...) return -1; } - va_start(args, fmt); outsize = vsnprintf(buf, bufsize, fmt, args); - va_end(args); if (outsize == -1) { /* Clear indication that output was truncated, but no @@ -364,6 +361,20 @@ xasprintf(char **strp, const char *fmt, ...) return 0; } +int +xasprintf(char **strp, const char *fmt, ...) +{ + va_list args; + int rval; + + va_start(args, fmt); + rval = xvasprintf(strp, fmt, args); + va_end(args); + + return rval; + +} + /* * Duplicate a pascal string into a normal C string. */ -- 2.30.2